﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Card.aspx.cs" Inherits="ExtSite.Card" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script src="JS/global.js" type="text/javascript"></script>

    <script src="JS/card2.js" type="text/javascript"></script>

    <script language="javascript" type="text/javascript">
        var s = null;
        function setStoreCard(sto) {
            s = sto;
        }
        function stoCardDataRefresh() {
            var args = arguments;
            var r = arguments[0].getAt(0);
            var f = Ext.ComponentQuery.query('form');
            if (r == null) {
                arguments[0].insert(0, {});
                r = arguments[0].getAt(0);
            }
            for (var ix = 0; ix < f.length; ix++) {
                f[ix].loadRecord(r);
            }
        }
        function tbarEdit_Click() {
            var args = arguments;
            var u = window.location;
            u += "&edi=1";
            window.location = u;
        }
        function tbarSave_Click() {
            var args = arguments;
            var f = Ext.ComponentQuery.query('form');
            var isu = false;
            for (var ix = 0; ix < f.length; ix++) {
                if (f[ix].getValues(false, true, false, true) != "") {
                    var d = f[ix].getValues(false, true, false, true);
                    for (var fi in d) {
                        f[ix].getRecord().set(fi, d[fi]);
                        isu = true;
                    }
                    
                }
            }
            if (!isu) {
                var g = Ext.ComponentQuery.query('grid');
                for (var ix = 0; ix < g.length; ix++) {
                    g[ix].store.sync();
                }
            }
            else {
                s.sync({
                    success: stoCard_Sync_Success,
                    failure: stoCard_Sync_Failure,
                    scope: window
                });
            }

        }
        function tbarInsert_Click() {
            var args = arguments;
            var f = Ext.ComponentQuery.query('form');
            var r = null;
            s.removeAll();
            s.insert(0, {});
            r = s.getAt(0);
            for (var ix = 0; ix < f.length; ix++) {
                f[ix].loadRecord(r);
            }
            var g = Ext.ComponentQuery.query('grid');
            for (var ix = 0; ix < g.length; ix++) {
                g[ix].store.removeAll();
            }

        }
        function tbarDelete_Click() {
            var g = Ext.ComponentQuery.query('grid');
            for (var ix = 0; ix < g.length; ix++) {
                g[ix].store.removeAll();
                g[ix].store.sync();
                if (ix == g.length - 1) {
                    g[ix].store.sync({ success: stoCard_Sync_Success,
                        failure: stoCard_Sync_Failure,
                        scope: window
                    });
                }
            }
        }
        function stoCard_Sync_Success() {
            var g = Ext.ComponentQuery.query('grid');
            for (var ix = 0; ix < g.length; ix++) {
                g[ix].store.sync();
            }
        }
        function stoCard_Sync_Failure() {

        }
        function stoLines_Sync_Success() {
            s.removeAt(0);
            s.sync();
        }
        function stoLines_Sync_Failure() {

        }
        
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManagerMain" runat="server" />
    <ext:Viewport Layout="VBoxLayout" runat="server" ID="ViewPortMain">
        <LayoutConfig>
            <ext:VBoxLayoutConfig Align="Stretch" ShrinkToFit="true" />
        </LayoutConfig>
        <Items>
            <ext:Toolbar runat="server" ID="ToolbarMain" Height="30">
                <Items>
                    <ext:Button ID="tbarInsert" runat="server" Text="New" Icon="PageAdd">
                        <Listeners>
                            <Click Fn="tbarInsert_Click">
                            </Click>
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="tbarEdit" runat="server" Text="Edit" Icon="PageEdit">
                        <Listeners>
                            <Click Fn="tbarEdit_Click">
                            </Click>
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="tbarSave" Text="Save" runat="server" Icon="Disk">
                        <Listeners>
                            <Click Fn="tbarSave_Click">
                            </Click>
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="tbarDelete" runat="server" Text="Delete" Icon="Delete">
                        <Listeners>
                            <Click Fn="tbarDelete_Click">
                            </Click>
                        </Listeners>
                    </ext:Button>
                </Items>
            </ext:Toolbar>
            <ext:Panel runat="server" ID="PanelMain" Flex="1" AutoScroll="true">
                <Items>
                </Items>
            </ext:Panel>
        </Items>
    </ext:Viewport>
    </form>
</body>
</html>
